package com._51cto.healthy.controller;

import com._51cto.healthy.content.P;
import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.Sport;
import com._51cto.healthy.service.SportService;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sport")
public class SportController {
    @DubboReference
    private SportService sportService;

    @GetMapping("/page/{pageSize}/{pageNum}")
    public R findAll(@RequestParam(value = "query",required = false)String query,
                     @PathVariable("pageSize")Integer pageSize,
                     @PathVariable("pageNum")Integer pageNum){

        P<Sport> all = sportService.findAll(query, pageSize, pageNum);
        return R.success(all);

    }
    //搜索
    @GetMapping("/search")
    public R search(@RequestParam("query")String query){
        List<Sport> list=sportService.searchByName(query);
        return R.success(list);

    }
    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Integer id){
        sportService.deleteByPK(id);
        return R.success("删除成功!!!");
    }
    //添加运动
    @PostMapping
    public R insert(@RequestBody Sport sport){
        sportService.insert(sport);
        return R.success("添加成功");

    }
    //修改运动
    @PutMapping
    public R update(@RequestBody Sport sport) {
        sportService.update(sport);
        return R.success("修改信息成功");
    }
}
